package connect;
import org.hibernate.Session;    
import org.hibernate.SessionFactory;    
import org.hibernate.cfg.Configuration;    
    
import model.User;    
    
public class Client {    
	public static void main(String[] args) {
		Configuration config = new Configuration().configure();
        SessionFactory sessionFactory = config.buildSessionFactory(); 
		Session session = null;
		try {
			session = sessionFactory.openSession(); 
			session.beginTransaction(); 
			User user = new User();
			user.setUsername("杨青云");
			user.setGender("男");
			user.setAge(23);
			user.setEmail("65789213@qq.com");
			user.setRegdatetime("2015-10-2");
			user.setPassword("1234");
			session.save(user); 
			//session.saveOrUpdate(user);  
			session.getTransaction().commit();

		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		} finally {
			if (session != null) {
				if (session.isOpen()) {
					session.close(); 
				}
			}
		}
	}
}

